/**
 * 获取增强版的文件名（移除最后的下划线及之后到后缀名的部分）
 * @param {string} name - 原始文件名或路径
 * @returns {string} 处理后的文件名
 */
export function getEnhancedFileName(name) {
  // 你的函数实现
  try {
    name = decodeURIComponent(name);
  } catch (e) {
    console.warn('URL解码失败:', e);
  }

  const questionMarkIndex = name.indexOf('?');
  if (questionMarkIndex > -1) {
    name = name.substring(0, questionMarkIndex);
  }

  let fileName = name;
  if (name.lastIndexOf("/") > -1) {
    fileName = name.slice(name.lastIndexOf("/") + 1);
  } else if (name.lastIndexOf("\\") > -1) {
    fileName = name.slice(name.lastIndexOf("\\") + 1);
  }

  const lastUnderscoreIndex = fileName.lastIndexOf('_');
  const lastDotIndex = fileName.lastIndexOf('.');

  if (lastUnderscoreIndex > -1 && lastDotIndex > lastUnderscoreIndex) {
    return fileName.substring(0, lastUnderscoreIndex) + fileName.substring(lastDotIndex);
  }

  return fileName;
}
